//
//  TXTabbar.swift
//  MicroBlog
//
//  Created by Jokin on 2017/3/26.
//  Copyright © 2017年 jokin. All rights reserved.
//

import UIKit

class TXTabbar: UITabBar {

    lazy var composeButton: UIButton = {
        let btn = UIButton()
        btn.addTarget(self, action: #selector(touchAddBtn), for: .touchUpInside)
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button"), for: .normal)
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), for: .highlighted)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), for: .normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), for: .highlighted)
        btn.sizeToFit()
        return btn
        
    }()
    
    func touchAddBtn()  {
        print("点击了加号按钮")
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        creatUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
        
    }
    
    func creatUI() {
        
        
        addSubview(composeButton)
        
        
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        var index = 0
        composeButton.centerX = self.centerX
        composeButton.centerY = self.height / 2
        for subView in subviews {
            if subView.isKind(of: NSClassFromString("UITabBarButton")!) {
                subView.width = self.width / 5
                subView.x = CGFloat(index) * (self.width / 5)
                index += 1
                if index == 2 {
                    index += 1
                }
            }
            
            
        }
    }
    
    
    
    

}
